<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <th:block th:include="include :: header('新增项目')" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>日历</title>

    <link
      th:href="@{/ajax/libs/jQuery-calendar20160330/easyui.css}"
      rel="stylesheet"
    />

    <script
      th:src="@{/ajax/libs/jQuery-calendar20160330/js/jquery-1.8.3.min.js}"
    ></script>
    <script
      th:src="@{/ajax/libs/jQuery-calendar20160330/js/jquery.easyui.min.js}"
    ></script>
    <script
      th:src="@{/ajax/libs/jQuery-calendar20160330/js/jquery.fullcalendar.js}"
    ></script>
    <script>
      $(function() {
        $(".footer").hide();
      });
    </script>
    <style>
      .calendar-body td {
        width: 14.2%;
        height: 16.6%;
        position: relative;
      }
      .work-time {
        font-size: 13px;
        position: absolute;
        top: 2px;
        left: 30px;
        font-style: normal;
        font-weight: bold;
        color: #3c8dbc;
      }
    </style>
  </head>

  <body class="easyui-layout">
    <div region="center" style="width: 300px;height: 300px;">
      <div
        class="easyui-fullCalendar"
        fit="true"
        style="width: 300px;height: 300px;overflow-y: auto"
      ></div>
    </div>
    <!--</div>-->
    <div th:include="include::footer"></div>
  </body>

  <script>
    var prefix = ctx + "system/hxDayReport";
    var month_map = {
      一月: "1",
      二月: "2",
      三月: "3",
      四月: "4",
      五月: "5",
      六月: "6",
      七月: "7",
      八月: "8",
      九月: "9",
      十月: "10",
      十一月: "11",
      十二月: "12"
    };
    var month_ = new Date().getMonth() + 1;
    var year_ = new Date().getFullYear();
    $(function() {
      getajaxDate(month_, year_);

      clickOtherMonth();
      hideNL();
      $(".calendar-header a").bind("click", function() {
        hideNL();
        clickOtherMonth();
      });
      $(
        ".calendar-prevmonth,.calendar-nextmonth,.calendar-prevyear,.calendar-nextyear"
      ).bind("click", function() {
        setTimeout(function() {
          month_ = $(".calendar-month").html();
          year_ = $(".calendar-year")
            .html()
            .substring(0, 4);
          getajaxDate(month_map[month_], year_);
        }, 500);
      });
    });
    function hideNL() {
      setTimeout(function() {
        dialogContent();
      }, 800);
      var obj = $(".calendar-body td").find("span[size=2]");
      var obj1 = $(".calendar-body td").find("span[color='#E0366E']");
      obj.addClass("hide");
      obj1.addClass("hide");
    }
    function clickOtherMonth() {
      $(".calendar-body .calendar-other-month").bind("click", function() {
        hideNL();
        clickCallback(clickOtherMonth);
        setTimeout(function() {
          month_ = $(".calendar-month").html();
          year_ = $(".calendar-year")
            .html()
            .substring(0, 4);
          getajaxDate(month_map[month_], year_);
        }, 500);
      });
    }
    function clickCallback(callback) {
      callback();
    }
    function setDateWork(data) {
      var arrTd = $(".calendar-body")
        .find("td")
        .not(".calendar-other-month");
      for (var i = 0; i < arrTd.length; i++) {
        arrTd
          .eq(i)
          .find("span")
          .eq(0)
          .addClass("month_font");
        arrTd
          .eq(i)
          .find("span")
          .eq(0)
          .siblings()
          .remove();
      }
      for (var i = 0; i < arrTd.length; i++) {
        var date = arrTd[i].abbr;
        var dataSplits = date.split("-");
        var zhmonth = dataSplits[1];
        var zhday = dataSplits[2];
        if (parseInt(dataSplits[1]) < 10) {
          zhmonth = "0" + dataSplits[1];
        }
        if (parseInt(dataSplits[2]) < 10) {
          zhday = "0" + dataSplits[2];
        }
        date = dataSplits[0] + "-" + zhmonth + "-" + zhday;
        // arrTd.eq(i).append("<i title='添加' class='fa fa-plus btn-add' abbr='" + date + "'></i><i title='查看' class='fa fa-eye btn-detail' abbr='" + date + "'> </i>");
        arrTd
          .eq(i)
          .append(
            "<i title='添加' class='fa fa-plus btn-add' abbr='" +
              date +
              "'></i>"
          );
        let workTime = 0;
        for (var j = 0; j < data.length; j++) {
          if (date == data[j].workDate) {
            workTime += data[j].workTime;
            var workDescArr = data[j].workDesc.split("@@");
            for (var k = 0; k < workDescArr.length; k++) {
              if (workDescArr[k].length >= 16) {
                var workDescSplit = workDescArr[k].substring(0, 11) + "...";
                arrTd
                  .eq(i)
                  .append(
                    "<br><a title='点击编辑'  class='work_font btn-edit'  projectId='" +
                      data[j].projectId +
                      "' abbr='" +
                      date +
                      "' >" +
                      workDescSplit +
                      "</a>"
                  );
              } else {
                arrTd
                  .eq(i)
                  .append(
                    "<br><a title='点击编辑'  class='work_font btn-edit' projectId='" +
                      data[j].projectId +
                      "' abbr='" +
                      date +
                      "' >" +
                      workDescArr[k] +
                      "</a>"
                  );
              }
            }
          }
        }
        if (workTime > 0) {
          arrTd
            .eq(i)
            .append("<i class='work-time'>已填报 " + workTime + " 工时</i>");
        }
      }
    }
    //function editOneContent(obj){

    //}

    function getajaxDate(month, year) {
      $.ajax({
        type: "post",
        url: prefix + "/listDaysReport",
        data: {
          month: month,
          year: year
        },
        success: function(data) {
          setDateWork(data.rows);
        }
      });
    }
    function dialogContent() {
      $(".btn-add").bind("click", function() {
        var selectDate = $(this).attr("abbr");
        $.modal.open(
          selectDate + "-新增日报",
          prefix + "/add/?dateStr=" + selectDate,
          800,
          600
        );
      });
      $(".btn-detail").bind("click", function() {
        var selectDate = $(this).attr("abbr");
        $.modal.open(
          selectDate + "-工作详情",
          prefix + "/viewToday/?dateStr=" + selectDate,
          650,
          450
        );
      });

      $(".btn-edit").bind("click", function() {
        var selectDate = $(this).attr("abbr");
        var projectId = $(this).attr("projectId");
        $.modal.open(
          selectDate + "-编辑日报",
          prefix +
            "/editOne/?dateStr=" +
            selectDate +
            "&projectId=" +
            projectId,
          800,
          600
        );
      });
    }
  </script>
</html>
